The present invention relates generally to computer software. More particularly, it relates to data storage structures.
In the field of software programming, various types of data structures may be used by software applications depending upon the application""s needs. Examples of commonly used data structures include hash tables, lists, sets, queues, arrays, trees, and more exotic data structures, such as black, red, etc. Every data structure has advantages and disadvantages. Some data structures are good for storing data, but not for retrieving data. For example, a data structure that stores data more efficiently than other types might require greater than average time to retrieve data. The opposite of the space versus time relationship might be true for other data structures. For example a data structure that provides quick retrieval access might require greater than average memory storage space.
Under existing methods and systems, a programmer using data structures must select a particular type of data structure during programming. For example in C++ language, an array data structure might be selected by the command, xe2x80x9cArray myarray=newArray( . . . );xe2x80x9d. A disadvantage of existing methods is that the data structure must be selected on the xe2x80x9cfront endxe2x80x9d of the design, during programming. If it is later determined that the data structure is not optimum for the data used at run-time, it is necessary to rewrite and recompile the software using a different data structure.
A more flexible method of selecting a data structure is to use an object factory to delay the choice of data structure and to make it somewhat easier to change the data structure at a later time. For example, container data structures are common in the standard C++ template library. The programmer asks the object factory for a particular data structure. The array selection example in C++ language might involve the commands, xe2x80x9cObjectFactory *ofp=. . . ; Array myArray=ofp - greater than createArray ( . . . );xe2x80x9d. For example, instead of creating an array directly, a programmer could call an object factory createArray method instead. This way, if the programmer later decides to change the implementation of the array, the only place where the code needs to be changed is in the object factory createArray method and the array implementation itself. The programmer does not have to go back and change every single call that creates a new array. This solution is still limited because the program has to be recompiled to take advantage of the new array implementation. The solution is also limited because the programmer still expects to deal with an array and is so limited to the interface an array provides. What is needed is a method and system for more efficiently changing the type of data structure to optimize the structure to the application.
A method and system are disclosed for creating and using a generic container as a data structure used in a software program. The data structure may be specified at start-up time or run-time. If the nature of the data changes from one run to another, the data structure may be adapted to a specific set of data. Existing data structures are abstracted to a generic interface for use with the container. The program interacts with the generic container using the generic interface, which allows the container to add, delete, and look up data stored in the container and to retrieve a key used by the container. A program uses an object factory to create an instance of a generic container having the generic interface. A mapping table, or other data structure, is maintained to map a container creation call to the appropriate container. At run-time, the object factory refers to the mapping table to determine what type of data structure to create. For a very simple program that only uses one data structure the mapping table would contain only one entry. For a more complex program that has several subsystems, each one with its own specific storage requirements, the mapping table could have a different entry for each subsystem. The specified data structures may be changed by changing the entries in the mapping table.